package org.yaac.server.egql;

import java.io.Serializable;
import java.util.List;

import org.yaac.server.egql.exception.EGQLException;
import org.yaac.server.egql.processor.Processor;

/**
 * @author Max Zhu (thebbsky@gmail.com)
 *
 */
public abstract class Statement implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	private String rawStatement;

	public String getRawStatement() {
		return rawStatement;
	}

	public void setRawStatement(String rawStatement) {
		this.rawStatement = rawStatement;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((rawStatement == null) ? 0 : rawStatement.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Statement other = (Statement) obj;
		if (rawStatement == null) {
			if (other.rawStatement != null)
				return false;
		} else if (!rawStatement.equals(other.rawStatement))
			return false;
		return true;
	}

	@Override
	public String toString() {
		return "Statement [rawStatement=" + rawStatement + "]";
	}

	/**
	 * no syntax checking, only logical error is checked here
	 * 
	 * @throws EGQLException
	 */
	public abstract void validate() throws EGQLException;
	
	/**
	 * @return true if this statement can be finished in single request, don't bother with pipeline / mapreduce in that case
	 */
	public abstract boolean isSimpleStatement();
	
	public abstract List<Processor> generateProcessors();
}
